package com.ruoyi.web.service.impl;

import com.ruoyi.common.enums.ReportSummeryType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.dao.ReportSummeryDao;
import com.ruoyi.web.entity.ReportSummeryEntity;
import com.ruoyi.web.helper.ReportSummerySqlProvider;
import com.ruoyi.web.mapper.ReportSummeryMapper;
import com.ruoyi.web.service.ReportSummerService;
import com.ruoyi.web.wrapper.ReportSummeryQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ：wang.j.f
 * @description：TODO
 * @date ：Created in 2021/6/27 11:50
 * @modified By：
 * @version: 1.0$
 */
@Service
public class ReportSummerServiceImpl implements ReportSummerService {

    @Resource
    private ReportSummeryMapper reportSummeryMapper;
    @Resource
    private ReportSummeryDao reportSummeryDao;

    @Override
    public void batchInsert(List<ReportSummeryEntity> list) {
        reportSummeryDao.batchAdd(list);
    }

    public List<ReportSummeryEntity> getTotalSummeryByTime(String time, Integer statType) {
        ReportSummeryQuery summeryQuery = reportSummeryMapper.defaultQuery()
                .selectAll()
                .where()
                .reportTime().eq(time)
                .and
                .type().eq(statType)
                .end();
        List<ReportSummeryEntity> reportSummeryEntities = reportSummeryMapper.listEntity(summeryQuery);
        return reportSummeryEntities;
    }

    public void insert(ReportSummeryEntity reportSummeryEntity) {
        reportSummeryMapper.insert(reportSummeryEntity);
    }

    @Override
    public List<ReportSummeryEntity> selectBySelective(ReportSummeryEntity entity) {
        ReportSummeryQuery summeryQuery = reportSummeryMapper.defaultQuery().selectAll();
        if (StringUtils.isNotNull(entity.getUnitName())) {
            summeryQuery.where().unitName().eq(entity.getUnitName());
        }
        summeryQuery.orderBy.desc("report_time");
        List<ReportSummeryEntity> reportSummeryEntities = reportSummeryMapper.listEntity(summeryQuery);
        return reportSummeryEntities;
    }
}
